function maxValue(grid: number[][]): number {
    let row: number = 0;
    let col: number = 0;

    const m = grid.length - 1;
    const n = grid[0].length - 1;

    let res: number = 0;
    while (row < m + 1 && col < n + 1) {
        console.log(grid[row][col], row, col);
        if (row === m && col === n) {
            res += grid[row][col];
            break;
        } else if (row === m) {
            res += grid[row][++col];
        } else if (col === n) {
            res += grid[++row][col];
        } else if (row + 1 <= m && col + 1 <= n) {
            if (grid[row + 1][col] > grid[row][col + 1]) {
                res += grid[++row][col];
            } else {
                res += grid[row][++col];
            }
        }
        console.log(res)
    }

    console.log(res);
    return res;
}

maxValue([
    [1, 2, 5],
    [3, 2, 1]
]);
// 正确版
// function maxValue(grid: number[][]): number {
//     const m = grid.length, n = grid[0].length;
//     for (let i = 0; i < m; i++) {
//         for (let j = 0; j < n; j++) {
//             grid[i][j] += Math.max(i > 0 ? grid[i - 1][j] : 0, j > 0 ? grid[i][j - 1] : 0);
//         }
//     }
//     return grid[m - 1][n - 1];
// };

